//
//  KDPlatformFilterSectionView.m
//  M800Project
//
//  Created by 姚宗超 on 14/11/7.
//  Copyright (c) 2014年 姚宗超. All rights reserved.
//

#import "MPPlatformFilterSectionView.h"
#import "UIImage+Common.h"

@interface MPPlatformFilterSectionView ()
@property (nonatomic, strong)UIView* contentView;

@property (nonatomic, strong)UIImageView* bgImageView;
@property (nonatomic, strong)UIImageView* firstTopSeperatorView;
@property (nonatomic, strong)UIImageView* secondTopSeperatorView;


@end

@implementation MPPlatformFilterSectionView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        //
        [self setupUI];
        [self setupConstraint];
        [self setNeedsLayout];
        [self layoutIfNeeded];

        [self.bgImageView setImage:[UIImage imageFromColor:[UIColor whiteColor] imageSize:self.bgImageView.size]];
        [self.firstTopSeperatorView setImage:[UIImage imageFromColor:[UIColor colorWithHexString:kCellBorderColor] imageSize:self.firstTopSeperatorView.size]];
        [self.secondTopSeperatorView setImage:[UIImage imageFromColor:[UIColor colorWithHexString:kCellBorderColor] imageSize:self.secondTopSeperatorView.size]];
    }
    return self;
}

- (instancetype)init
{
    return [self initWithFrame:CGRectZero];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //
        [self setupUI];
        [self setupConstraint];
        [self setNeedsLayout];
        [self layoutIfNeeded];
        [self.bgImageView setImage:[UIImage imageFromColor:[UIColor whiteColor] imageSize:self.bgImageView.size]];
        [self.firstTopSeperatorView setImage:[UIImage imageFromColor:[UIColor colorWithHexString:kCellBorderColor] imageSize:self.firstTopSeperatorView.size]];
        [self.secondTopSeperatorView setImage:[UIImage imageFromColor:[UIColor colorWithHexString:kCellBorderColor] imageSize:self.secondTopSeperatorView.size]];

    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.contentView];
    [self.contentView addSubview:self.bgImageView];
    [self.contentView addSubview:self.firstTopSeperatorView];
    [self.contentView addSubview:self.secondTopSeperatorView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
}

- (void)setupConstraint
{
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.leading.trailing.mas_equalTo(self);
    }];
    
    [self.firstTopSeperatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(@(1.0f));
    }];
    
    [self.secondTopSeperatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.firstTopSeperatorView.mas_bottom).with.offset(10.0f);
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(@(1.0f));
    }];
    
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.secondTopSeperatorView.mas_bottom);
        make.leading.trailing.bottom.mas_equalTo(self.contentView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView).with.offset(5.0f);
        make.leading.mas_equalTo(self.contentView).with.offset(10.0f);
//        make.bottom.mas_equalTo(self.contentView).with.offset(-15.0f);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView).with.offset(5.0f);
        make.trailing.mas_equalTo(self.contentView).with.offset(-10.0f);
        make.leading.mas_equalTo(self.titleLabel.mas_trailing).with.offset(10.0f);
    }];
}

#pragma mark - property

- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
    }
    return _contentView;
}

- (UIImageView *)bgImageView
{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
    }
    return _bgImageView;
}

- (UIImageView *)firstTopSeperatorView
{
    if (!_firstTopSeperatorView) {
        _firstTopSeperatorView = [[UIImageView alloc] init];
    }
    return _firstTopSeperatorView;
}

- (UIImageView *)secondTopSeperatorView
{
    if (!_secondTopSeperatorView) {
        _secondTopSeperatorView = [[UIImageView alloc] init];
    }
    return _secondTopSeperatorView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.textColor = [UIColor colorWithHexString:kContentTextColor];
        _titleLabel.font = [UIFont systemFontOfSize:kContentFontSize];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.text = @"测试";
    }
    return _titleLabel;
}

- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _contentLabel.textColor = [UIColor colorWithHexString:kTextUnSelectedGrayColor];
        _contentLabel.font = [UIFont systemFontOfSize:kDescribeFontSize];
        _contentLabel.textAlignment = NSTextAlignmentRight;
        _contentLabel.text = @"测试";
    }
    return _contentLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
